<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>$!app_name</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<!-- 框架 -->
    <link href="${base}/include/css/msg.css" rel="stylesheet" type="text/css"/>

    <link href="${base}/include/css/default.css" rel="stylesheet" type="text/css"/>
	<script type='text/javascript'>
		var CONTEXTPATH = '${base}';
	</script>
    <script src="${base}/include/js/main.js"></script>
    <script src="${base}/include/js/string.js"></script>
	<!-- 分页  注意顺序 -->
	<link href="${base}/include/css/themes/gray/easyui.css" rel="stylesheet" type="text/css"/> 	
	<script src="${base}/include/js/jquery.easyui.min.js"></script>	
    <!-- 树 -->
    <script type="text/javascript" src="${base}/include/controls/ztree/jquery.ztree.core-3.5.min.js"></script> 
	<link rel="stylesheet" href="${base}/include/controls/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
    <SCRIPT type="text/javascript">
           <!--
           var setting = {
                        async: {
                            enable: true,
                            url:"${base}/private/sys/user/tree",
                            autoParam:["id"]
                        },
                        view:{
                             nameIsHTML: true
                        }
                    };
           function initTree(){
        	    var myTree =jQuery.fn.zTree.init(jQuery("#treeDemo"), setting);
			}
           
           function add()
           {           
				if(Page.getValue("unitid")=="")
				{
					Dialog.alert("请先选择单位！");
					return;
				}
            	var d = new Dialog("Add");
               	d.Width = 630;
               	d.Height = 490;
               	d.Title = "新建用户";
               	d.URL = "${base}/private/sys/user/toadd?unitid="+Page.getValue("unitid"); 
               	d.onLoad =function(){
               		$DW.$Z("loginname").focus();
               	};
               	d.OKEvent = function(){
               		addSave();
               	};    	    		
               	 
               	d.show();
           }

           function addSave(){     
           	if($DW.Verify.hasError()){
           	  	return;
             } 
           	jQuery.ajax({
        		url : "${base}/private/sys/user/ajaxname",
        		data : $DW.$("#form1").serialize(),
        		success : function (res) {	
        			if(res=="true"){
        				Dialog.alert("用户名已存在");	
        				return;
        			} else{
        				doit();
        			}	 
        			
        		},
        		fail : function(res) {
        			Dialog.alert("系统错误?!");
        		}
        	}); 
           	 
           	 
           } 
           function doit(){
        	   if ($DW.$("#unitid").val()=="")
   		    {
   		         Dialog.alert("请选择机构！");
   		         return ;
   		    }
   		    
   		    if ($("#password").val()==$("#password2").val()){
   		    	$DW.getIdsTree();                
   		        }else{
   		            Dialog.alert("两次输入密码不一致！");
   		            $DW.$("#password2").focus();
   		            return;
   		    } 
   		    jQuery.ajax({
          		 	type: 'POST',
          			url : "${base}/private/sys/user/add" ,
          			data : $DW.$("#form1").serialize(),
          			success : function (res) { 
          				if(res=="true"){
          					$D.close();
          					Dialog.alert("添加成功！");
          					loadGrid(Page.getValue("unitid"));
          				}else{
          					Dialog.alert("添加失败！");
          				}
          			},
          			fail : function(res) {
          				Dialog.alert("系统错误?!");
          			}
          		});
           }
           function toupdate()
           {
               var arr = $('#dg1').datagrid('getSelected'); 
               if (!arr || arr.length == 0) {
                   Dialog.alert("请先选择要编辑的用户！");
                   return;
               }
               var d = new Dialog("Update");
               d.Width = 630;
               d.Height = 460;
               d.Title = "编辑用户" + arr.id;
               d.URL = "${base}/private/sys/user/toupdate?userid="+arr.id;
           	   d.OKEvent = function(){
           			updateSave();
           	   };
               d.show();
           }
           function toupdateId(id)
           {
           		
               if (!id || id.length == 0) {
                   Dialog.alert("请先选择要编辑的用户！");
                   return;
               }
               var d = new Dialog("Update");
               d.Width = 630;
               d.Height = 460;
               d.Title = "编辑用户" + id;
               d.URL = "${base}/private/sys/user/toupdate?userid="+id;    	
           	   d.OKEvent = function(){
           			updateSave();
           	   };
               d.show();
           }
           function updateSave(){     
        		if($DW.Verify.hasError()){
        		  return;
        	     } 
        		 if($DW.dosave()){
        		 jQuery.ajax({
        			 	type: 'POST',
        				url : "${base}/private/sys/user/update" ,
        				data : $DW.$("#form1").serialize(),
        				success : function (res) { 
        					if(res=="true"){
        						$D.close();
        						Dialog.alert("更新成功！");
        						loadGrid();
        					}else{
        						Dialog.alert("更新失败！");
        					}
        					 
        					return false;
        				},
        				fail : function(res) {
        					Dialog.alert("系统错误!");
        				}
        			});
        		 }
        	}
           function del(){
        	    var ids = [];
        		var arr = $('#dg1').datagrid('getSelections');
        	    if (!arr || arr.length == 0) {
        	        Dialog.alert("请先选择要删除的用户！");
        	        return;
        	    }
        	    for(var i=0; i<arr.length; i++){
        	        ids.push(arr[i].id);
					if(arr[i].id=="10000"){
						Dialog.alert("超级管理员不可删除！");
						return;
					}
        	    }
        	    Dialog.confirm("确定删除？", function(){
        	    	jQuery.ajax({
        	    	 	type: 'POST',
        	    		url : "${base}/private/sys/user/delete?ids="+ids ,    		
        	    		success : function (res) { 
        	    			if(res=="true"){    				
        	    				Dialog.alert("删除成功！");
        	    				loadGrid();
        	    			}else{
        	    				Dialog.alert("删除失败！");
        	    			}			 
        	    			return false;
        	    		},
        	    		fail : function(res) {
        	    			Dialog.alert("系统错误!");
        	    		}
        	    	});
        	    }, "", 250, 150);    
        	}


        	function  locked(){
        	    var ids = [];
        		var arr = $('#dg1').datagrid('getSelections');
        	    if (!arr || arr.length == 0) {
        	        Dialog.alert("请先选择要禁用的用户！");
        	        return;
        	    }
        	    for(var i=0; i<arr.length; i++){
        	        ids.push(arr[i].id);
                    if(arr[i].id=="10000"){
                        Dialog.alert("超级管理员不可禁用！");
                        return;
                    }
        	    }
        	    Dialog.confirm("确定禁用？", function(){
        	    	jQuery.ajax({
        	    	 	type: 'POST',
        	    		url : "${base}/private/sys/user/lock?ids="+ids ,    		
        	    		success : function (res) { 
        	    			if(res=="true"){    				
        	    				Dialog.alert("禁用成功！");
        	    				loadGrid();
        	    			}else{
        	    				Dialog.alert("禁用失败！");
        	    			}			 
        	    			return false;
        	    		},
        	    		fail : function(res) {
        	    			Dialog.alert("系统错误!");
        	    		}
        	    	});
        	    }, "", 250, 150);
        	    }
        	    
        	  function unlocked(){
            	    var ids = [];
            		var arr = $('#dg1').datagrid('getSelections');
        	        if (!arr || arr.length == 0) {
        	            Dialog.alert("请先选择要启用的用户！");
        	            return;
        	        }
            	    for(var i=0; i<arr.length; i++){
            	        ids.push(arr[i].id);
            	    }
        	        Dialog.confirm("确定启用？", function(){
        	        	jQuery.ajax({
        	        	 	type: 'POST',
        	        		url : "${base}/private/sys/user/unlock?ids="+ids ,    		
        	        		success : function (res) { 
        	        			if(res=="true"){    				
        	        				Dialog.alert("启用成功！");
        	        				loadGrid();
        	        			}else{
        	        				Dialog.alert("启用失败！");
        	        			}			 
        	        			return false;
        	        		},
        	        		fail : function(res) {
        	        			Dialog.alert("系统错误!");
        	        		}
        	        	});
        	        }, "", 250, 150); 
        	    }
        	    
           function initButton(){
        	   Page.initBtn();
        	   $!initBtn
           }
           function list(unitid){
        	   Page.setValue("SearchUserName","");
			   Page.setValue("unitid",unitid);
        	   jQuery.ajax({
          		 	type: 'POST',
          			url : "${base}/private/sys/user/getuname" ,
          			data : {"unitid":unitid},
          			success : function (res) {        	
          				          				
          				Page.setValue("unitname",res);
          				loadGrid();
          				 
          			},
          			fail : function(res) {
          				Dialog.alert("系统错误?!");
          			}
          		});
        	    
           }
           function getWidth(percent){
        	   return document.body.clientWidth*percent;
		   }
           function loadGrid(){
			   var SearchUserName=Page.getValue("SearchUserName");
        	   $("#dg1").datagrid({  
        	        width:"auto",
        	   		height:"auto",
        	        nowrap: false,  
        	        striped: true,  
        	        border: true,  
        	        collapsible:false,//是否可折叠的  
        	        fit: true,//自动大小  
        	        url:"${base}/private/sys/user/list?unitid="+Page.getValue("unitid")+"&lock="+Page.getValue("lock"),  
        	        
        	        queryParams:{"SearchUserName":SearchUserName},		
        	        //sortName: 'code',  
        	        //sortOrder: 'desc',  
        	        remoteSort:false,   
        	        idField:"id",
        	        singleSelect:false,//是否单选  
        	        pagination:true,//分页控件  
        	        rownumbers:true,//行号  
        	        fitColumns: true,//行自适应
					pageSize: 10,
        	        pageList:[5,10,15,20,30,40,50],
        	        loadMsg:'数据加载中...',
        	        onDblClickRow:function(rowIndex,row)
        	        {
        	        	toupdateId(row.id);
        	        },
        	        columns:[[
						{title : '用户名',field : 'loginname',width:getWidth(0.08),align : 'left'},
						{title : '姓名',field : 'realname',width:getWidth(0.08),align : 'left'},
						{title : '帐户状态',field : 'state',align : 'left',
								formatter:function(value,rec,index){
	            					if(rec.state==1)
	            					{
										return '<font color="red">禁用</font>';
	            					}
	            					else
	            					{
	            						return '正常';
	            					}
       					}},
						{title : '职务',field : 'pozition',width:getWidth(0.10),align : 'left'},
						{title : '电子邮件',field : 'email',width:getWidth(0.10),align : 'left'},
						{title : '固定电话',field : 'telephone',width:getWidth(0.10),align : 'left'},
						{title : '手机号码',field : 'mobile',width:getWidth(0.10),align : 'left'}   
        	        ]],
        	        frozenColumns:[[  
        	            {field:"id",checkbox:true}
        	        ]]
        	    });  
        	    //设置分页控件  
        	    var p = $("#dg1").datagrid("getPager");  
        	    $(p).pagination({  
        	        beforePageText: "第",//页数文本框前显示的汉字  
        	        afterPageText: "页    共 {pages} 页",  
        	        displayMsg: "当前显示 {from} - {to} 条记录   共 {total} 条记录",  
        	        onBeforeRefresh:function(){ 
        	            //$(this).pagination('loading'); 
        	             
        	            //$(this).pagination('loaded'); 
        	        } 
        	    });  
           }
           function lockSearch(){
        	   Page.setValue("lock","1");
        	   loadGrid();
        	   Page.setValue("lock","0");
           }
           Page.onLoad(function() {
        	   initTree();
        	   loadGrid();
        	   initButton();
               }); 
           $(window).resize(function () {
       		clearTimeout(timer);
       		timer=setTimeout(function(){
       		  $('#dg1').datagrid('resize');
       		  $('div.panel-body').css('width','auto'); //////
       		 },100);
       		});
           //-->
       </SCRIPT>
</head>
<body leftmargin="0" topmargin="0" style="overflow-x: hidden; overflow-y: auto">
	<table width="100%" border="0" cellspacing="6" cellpadding="0"
		style="border-collapse: separate; border-spacing: 6px;">
		<tr valign="top">
			<td width="180">
				<table width="210" height="100%" border="0" cellspacing="0"
					cellpadding="6" class="blockTable">
					<tr>
						<td style="padding: 6px;" class="blockTd">
							<div ztype='_Tree'
								style='-moz-user-select: none; height: 450px; width: 200px;'
								id='tree1' class='treeItemN'>

								<ul id="treeDemo" class="ztree"></ul>
							</div>

						</td>
					</tr>
				</table>
			</td>
			<td width="100%" valign="top"> 	
	<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse: separate; border-spacing: 0;">
    <tr valign="top">
      <td>
	   <form name="form1" id="form1" method="post" > 
        <input type="hidden" name="unitid" id="unitid" value="">
        <input type="hidden" name="lock" id="lock" value="0">
        <input type="hidden" name="checkids" id="checkids" value="">
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="blockTable">
                                      <tr>
                                        <td class="blockTd">
                                        
                                        <table width="100%" border="0" cellspacing="0" cellpadding="6" >
                                          <tr>
                                            <td valign="middle"><img src="${base}/images/icons/icon021a1.gif" width="20" height="20" />
                                            &nbsp;<span id="unitname">所有机构 </span>&nbsp;|&nbsp;<span>用户列表 </span></td>
                                          </tr>
                                          <tr>
                                            <td style="padding:0 8px 4px;"><a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn'
                                                          hidefocus='true' tabindex='-1' onselectstart='return false'
                                                          id='BtnAdd' onClick="add();"><img
                                src="${base}/images/icons/icon022a2.gif" width="20" height="20"/><b>新建&nbsp;</b></a> <a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn' hidefocus='true'
                               tabindex='-1' onselectstart='return false' id='BtnUpdate'
                               onClick="toupdate();"><img src="${base}/images/icons/icon022a4.gif" width="20"
                                                                                 height="20"/><b>编辑&nbsp;</b></a> 
                                                                                 <a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn' hidefocus='true'
                               tabindex='-1' onselectstart='return false' id='BtnDel'
                               onClick="del();"><img src="${base}/images/icons/icon022a3.gif"
                                                                                        width="20" height="20"/><b>删除&nbsp;</b></a>
                                 <a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn' hidefocus='true'
                                                                              tabindex='-1' onselectstart='return false' id='BtnLocked'
                                                                              onClick="locked();"><img src="${base}/images/icons/icon022a5.gif"
                                                                                                                                       width="20" height="20"/><b>禁用&nbsp;</b></a>
                                <a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn' hidefocus='true'
                                                                              tabindex='-1' onselectstart='return false' id='BtnUnlocked'
                                                                              onClick="unlocked();"><img src="${base}/images/icons/icon022a8.gif"
                                                                                                                                       width="20" height="20"/><b>启用&nbsp;</b></a>                
                  
                                              &nbsp;
                                              <input name="SearchUserName" type="text" id="SearchUserName"
			value="" placeholder="请输入用户名或姓名" style="width:110px">
                                              <input type="button" name="Submitbutton" id="Submitbutton" value="查询"
			onClick="loadGrid()">
									          <input type="button" name="lockbutton" id="lockbutton" value="查询被禁用用户"
			onClick="lockSearch()">
                                            </td>
                                          </tr>
                                          <tr>
                                            <td style="padding:0px 5px;" height="320" >                                             
                                            <table width="100%" height="100%" id="dg1" size="10" cellpadding="2" cellspacing="0">
												<tr><td></td></tr>
											</table>                                          
                                            </td>
                                          </tr>
                                        </table></td>
                                      </tr>
                                    </table>
                                    
	   </form>
	  </td>
    </tr>
 </table>

			</td>
		</tr>
	</table>
</body>
</html>